using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class HealthManager : MonoBehaviour, IDamage
{
    public static HealthManager Instance;
    public Image healthBar;
    public float currentHealth;
    public float maxHealth, healthBegin;
    public GameObject gameOverPanel;
    private void Awake()
    {
        Instance=this;
    }
    // Start is called before the first frame update
    void Start()
    {
        currentHealth = maxHealth;
    }

    private void Update()
    {
        healthBar.fillAmount = GetPercentage();
        AddHealth(healthBegin * Time.deltaTime);
    }
    public void AddHealth(float amount)
    {
        currentHealth = Mathf.Min(currentHealth + amount, maxHealth);
    }

    public float GetPercentage()
    {
        return currentHealth / maxHealth;
    }

    public void Die()
    {
        Debug.Log("Player is Dead");
        gameOverPanel.SetActive(true);
        PlayerCon.isPause = true;
        Time.timeScale = 0;
    }

    public void Takemage(float amount)
    {
        Debug.Log("����ܻ�");
        currentHealth = Mathf.Max(currentHealth - amount, 0.0f);
        if (currentHealth <=0)
            Die();
    }
}

public interface IDamage
{
    void Takemage(float amount);
}